package pl.polsl.mmm.projectcomm.data;

import static android.opengl.GLES20.*;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

//import pl.polsl.mmm.projectcomm.util.LoggerConfig;

import static pl.polsl.mmm.projectcomm.Constants.BYTES_PER_FLOAT;;

public class VertexArray {
	private final FloatBuffer floatBuffer;

    public VertexArray(int length) {
        floatBuffer = ByteBuffer
                .allocateDirect(length * BYTES_PER_FLOAT)
                .order(ByteOrder.nativeOrder())
                .asFloatBuffer();
        floatBuffer.position(0);
    }

	public VertexArray(float[] vertexData){
		floatBuffer = ByteBuffer
				.allocateDirect(vertexData.length * BYTES_PER_FLOAT)
				.order(ByteOrder.nativeOrder())
				.asFloatBuffer()
				.put(vertexData);

        //Log.w("VertexArray", Float.toString(floatBuffer.get(50)));
	}
	
	public void setVertexAttribPointer(int dataOffset, int attributeLocation, int componentCount, int stride) {
		floatBuffer.position(dataOffset);
		glVertexAttribPointer(attributeLocation, componentCount, GL_FLOAT, false, stride, floatBuffer);
		glEnableVertexAttribArray(attributeLocation);
		floatBuffer.position(0);
	}

    public void putAllData (float[] vertexData) {
        floatBuffer.position(0);
        floatBuffer.put(vertexData);
    }

    public void putData(float data) {
        floatBuffer.put(data);
    }

    public void reset() {
        floatBuffer.position(0);
    }
}
